package gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import world.*;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JScrollPane;

public class MainWindow extends JFrame {

	private CritterWorld world;
	private WorldViewPanel worldView;
	private ControlPanel controls;
	private InformationPanel info;
	private JScrollPane worldPane;
	private FileBarPanel fileBar;
	private final ActionListener pauseListener;
	
	public MainWindow(CritterWorld w){
		setSize(1000, 600);
		world = w;
		pauseListener = new UniversalPauseListener();
		Box mainBox = new Box(BoxLayout.X_AXIS);
		Box worldBox = new Box(BoxLayout.Y_AXIS);
		worldView = new WorldViewPanel(world);
		controls = new ControlPanel(world, worldView);
		info = new InformationPanel(world, worldView);
		add(mainBox);
		mainBox.add(worldBox);
		mainBox.add(controls);
		worldPane = new JScrollPane(worldView);
		fileBar = new FileBarPanel(world, this, worldView, pauseListener);
		worldBox.add(fileBar);
		worldBox.add(worldPane);
		worldBox.add(info);
		setTitle("Critter Simulation");
		setVisible(true);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
	}
	
	public void changeWorld(CritterWorld w){
		world = w;
		worldView.changeWorld(w);
		controls.changeWorld(w);
		info.changeWorld(w);
		fileBar.changeWorld(w);
	}
	
	private class UniversalPauseListener implements ActionListener{
		public void actionPerformed(ActionEvent e){
			controls.pauseWorld();
		}
	}
}
